package com.qiangzhi.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * 配置类 用于配置Knife4j生成接口文档
 */
@Configuration
public class Knife4jConfiguration {

    /**
     * 公共接口
     *
     * @return
     */
    @Bean
    public Docket commonDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("公共接口") // 配置api文档的分组
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qiangzhi.controller.common")) // 配置扫描路径
                .paths(PathSelectors.any()).build();
    }

    /**
     * 学生端接口
     *
     * @return
     */
    @Bean
    public Docket studentDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("学生端接口")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qiangzhi.controller.student"))
                .paths(PathSelectors.any()).build();
    }

    /**
     * 教师端端接口
     *
     * @return
     */
    @Bean
    public Docket teacherDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("教师端接口")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qiangzhi.controller.teacher"))
                .paths(PathSelectors.any()).build();
    }

    /**
     * 教务端接口
     *
     * @return
     */
    @Bean
    public Docket adminDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("教务端接口")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qiangzhi.controller.admin"))
                .paths(PathSelectors.any()).build();
    }

    /**
     * 基本信息
     *
     * @return
     */
    private ApiInfo apiInfo() {
        // 作者信息
        Contact contact = new Contact("fromdrowning",
                "https://gitee.com/fromdrowning/qiangzhi-academic-affairs",
                "1975865247@qq.com");
        return new ApiInfoBuilder()
                .title("强智教务系统项目接口文档")
                .version("1.0")
                .description("强智教务系统项目接口文档")
                .contact(contact).build();
    }

}
